/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution396 {

    public static void main(String args[]) {
        Solution396 s = new Solution396();
        System.out.println(s.maxRotateFunction(new int[]{4, 3, 2, 6}));
    }

    public int maxRotateFunction(int[] A) {
        int sum = 0;
        int sumPlus = 0;
        int n = A.length;
        for (int i = 0; i < n; i++) {
            sum += A[i];
            sumPlus += A[i] * i;
        }

        int maxv = sumPlus;

        for (int i = n - 1; i >= 0; i--) {
            int cv = sumPlus + sum - n * A[i];
            maxv = Math.max(cv, maxv);
            sumPlus = cv;
        }
        return maxv;
    }
}
